#pragma once

#include <xpam/misc/nocopy.h>
#include <xpam/ui/window.h>
#include <xpam/rectangle.h>

namespace xpam
{
    namespace ui
    {
        class dc : misc::nocopy
        {
            unsigned int * _buffer;
            unsigned int _width;
            unsigned int _height;
            void * _dc;
            void * _bitmap;
        public:
            dc();
            ~dc();
        public:
            void create(unsigned int w, unsigned int h);
            template<typename T1>
            void create(size<T1> & sz)
            {
                create(sz.width, sz.height);
            }
            void from_window(xpam::ui::window & w);
            void from_file(const std::string & filename);

        public:
            void * get_internal_handle() { return _dc; };
            unsigned int width() { return _width; };
            unsigned int height() { return _height; };
            unsigned int  * buffer() { return _buffer; };

            unsigned int * operator [] (int y) { return _buffer + (_height - y - 1) * _width; }
        public:
            void copy(dc & dc_);
            void copy_alpha(dc & other, const point<int> & pt);
            //void copy_transparent(dc & dc_);

            void fill(unsigned int color);
            void fill(unsigned int color, point<int> pt, size<int> sz);

            void draw_line(int x1, int y1, int x2, int y2);
            void draw_text(const xpam::rectangle<int> & rect, const std::string & text);
            void draw_text(const xpam::rectangle<int> & rect, const std::wstring & text);
            void color(int rgb);
            void color(int r, int g, int b);
        };
    }
}